﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace XHCTMS.VIEW
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

 

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            DataTable user = new BLL.User().GetUserInfo(this.txtUserName.Value, this.txtPassword.Value);
            if (user == null)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script>alert('网络连接错误')</script>");
                return;
            }
            if (user.Rows.Count == 0)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script>alert('账号密码错误')</script>");
                return;
            }

            Util.UserInfo userInfo = new Util.UserInfo();
            userInfo.UserID = user.Rows[0][0].ToString();
            userInfo.UserName = user.Rows[0][1].ToString();
            userInfo.UserJob = user.Rows[0][2].ToString();
            userInfo.UserTitle = user.Rows[0][3].ToString();
            userInfo.UserDep = user.Rows[0][4].ToString();
            Util.SetUserSession.userSession = userInfo;

            Util.SetUserCookie.userCookie = user.Rows[0][0].ToString();        
            Response.Redirect("Main.aspx");
        }
    }
}